import axios from 'axios'
// import {getToken} from './auth'
const request =  axios.create({
    timeout:5000
})

const token = sessionStorage.getItem('token')
//请求发出前拦截
request.interceptors.request.use(function(config){
    // console.log(token);
    if(token){
        //已经登录的请求头配置，主要用于登录成功后后台返回的token,做权限
        config.headers.authorization  = 'Bearer '+token; 
    }else{
        // 未登录的请求头配置
    }
    return config;
},function(error){
    return Promise.reject(error)
})
//请求响应拦截
request.interceptors.response.use(function(response){
    return response.data;
},function(error){
    return Promise.reject(error)
})

export default request
